<?php

// @formatter:off
/**
 * @file index.php
 * @author Alejandro Dario Simi
 * @date $Date: 2014-06-03 03:40:32 +0000 (Tue, 03 Jun 2014) $
 *
 * $Id: index.php 112 2014-06-03 03:40:32Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/trunk/frontview/layouts/index.php $
 */
// @formatter:on

class LayoutControllerIndex extends WCLayoutController {
	//
	// Magic methods.
	public function __construct() {
		parent::__construct();

		global $wcDefaults;

		if(isset($_REQUEST["removable"])) {
			$this->_selector["extra"] = "R";
		}
		if(isset($_REQUEST["editable"])) {
			$this->_selector["extra"] = "E";
		}
		if($wcDefaults["read-only"]) {
			$this->_selector["extra"] = "RO";
		}
	}
	//
	// Protected methods.
	protected function cleanCssClass($name) {
		return str_replace(array(" ", ":", "/"), "_", $name);
	}
	protected function loadHeaderExtras() {
		global $wcSkinDefaults;

		$this->_manager->header_styles = $wcSkinDefaults["header"]["styles"];
		$this->_manager->header_scripts = $wcSkinDefaults["header"]["scripts"];
	}
	protected function loadSuperCssClass() {
		$superClasses = array();

		//
		// Loading global shortcuts.
		global $wcAction;
		global $wcGroup;
		global $wcDirectory;
		global $wcTag;

		if($wcAction) {
			$superClasses[] = "wc-action-{$wcAction}";
		}

		$superClasses[] = "wc-group-{$wcGroup->name()}";
		$superClasses[] = "wc-groupid-{$wcGroup->id()}";

		if($wcDirectory && $wcDirectory->ok()) {
			$superClasses[] = "wc-directory-{$wcDirectory->name()}";
			$superClasses[] = "wc-directoryid-{$wcDirectory->id()}";
		}
		if($wcTag && $wcTag->ok()) {
			$superClasses[] = "wc-tag-{$wcTag->name()}";
			$superClasses[] = "wc-tagid-{$wcTag->id()}";
		}

		array_walk($superClasses, function(&$item) {
			$item = $this->cleanCssClass($item);
		});

		$this->_manager->css_super_class = implode(" ", $superClasses);
	}
	protected function subRun() {
		$ok = true;

		$this->loadSuperCssClass();
		$this->loadHeaderExtras();

		return $ok;
	}
}
